<?php

namespace D3hdv\HdvBundle\Entity;
use \Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class HdvCompte implements UserInterface // AJouter Date d'inscription
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;
    
    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $login;   


    
    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $password;   
 
    /**
     * @var string
     *
     * @ORM\Column(name="email", type="string", length=255)
     */
    protected $email;

   
    /**
     * @ORM\Column(type="string", length=255)
     *
     * @var string salt
     */
    protected $salt;

    /**
     * @ORM\ManyToMany(targetEntity="D3hdv\Diablo3Bundle\Entity\Role")
     *
     * @var ArrayCollection $userRoles
     */
    protected $userRoles;    

  
     /**
     * @ORM\ManyToOne(targetEntity="D3hdv\Diablo3Bundle\Entity\D3Compte")
     * @ORM\JoinColumn(nullable=true)
     */
    private $diablo3Compte;

    /**
     * @ORM\ManyToMany(targetEntity="D3hdv\HdvBundle\Entity\HdvNotification")
     * @ORM\JoinColumn(nullable=true)
     */
    private $notification;
    


       /**
	* @ORM\ManyToMany(targetEntity="D3hdv\HdvBundle\Entity\HdvVente",cascade={"persist"})
	*/
	private $ObjetsEnVente;

    public function __construct()
    {
        $this->createdAt = new \DateTime();
        $this->userRoles = new ArrayCollection();
	$this->ObjetsEnVente = new ArrayCollection();
        $this->updatedAt = new \DateTime();
    }    
    
    /**
     * Gets an array of roles.
     * 
     * @return array An array of Role objects
     */
    public function getRoles()
    {
        return $this->getUserRoles()->toArray();
    }
    
    /**
     * Gets the user roles.
     *
     * @return ArrayCollection A Doctrine ArrayCollection
     */
    public function getUserRoles()
    {
        return $this->userRoles;
    }
 
    /**
     * Compares this user to another to determine if they are the same.
     * 
     * @param UserInterface $user The user
     * @return boolean True if equal, false othwerwise.
     */
    public function equals(UserInterface $user)
    {
        return md5($this->getUsername()) == md5($user->getUsername());
    }
    
    
    /**
     * Gets the user password.
     *
     * @return string The password.
     */
    public function getPassword()
    {
        return $this->password;
    }
 
    /**
     * Sets the user password.
     *
     * @param string $value The password.
     */
    public function setPassword($value)
    {
        $this->password = $value;
    }
 
    /**
     * Gets the user salt.
     *
     * @return string The salt.
     */
    public function getSalt()
    {
        return $this->salt;
    }
 
    /**
     * Sets the user salt.
     *
     * @param string $value The salt.
     */
    public function setSalt($value)
    {
        $this->salt = $value;
    }
    
    /**
     * Gets the username.
     *
     * @return string The username.
     */
    public function getUsername()
    {
        return $this->login;
    }
 
    /**
     * Sets the username.
     *
     * @param string $value The username.
     */
    public function setUsername($value)
    {
        $this->login = $value;
    }    
    
    /**
     * Erases the user credentials.
     */
    public function eraseCredentials()
    {
 
    }   

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Add userRoles
     *
     * @param \D3hdv\Diablo3Bundle\Entity\Role $userRoles
     * @return D3Compte
     */
    public function addUserRole(\D3hdv\Diablo3Bundle\Entity\Role $userRoles)
    {
        $this->userRoles[] = $userRoles;
    
        return $this;
    }

    /**
     * Remove userRoles
     *
     * @param \D3hdv\Diablo3Bundle\Entity\Role $userRoles
     */
    public function removeUserRole(\D3hdv\Diablo3Bundle\Entity\Role $userRoles)
    {
        $this->userRoles->removeElement($userRoles);
    }

    /**
     * Set email
     *
     * @param string $email
     * @return D3Compte
     */
    public function setEmail($email)
    {
        $this->email = $email;
    
        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    public function serialize()
	{
		return serialize(array(
		$this->id,
		$this->password,
		$this->username,
		$this->email,
		$this->salt,
		$this->userRoles
		));
	}

	public function unserialize($serialized)
	{
		list(
		$this->id,
		$this->password,
		$this->username,
		$this->email,
		$this->salt,
		$this->userRoles
		) = unserialize($serialized);
	}
   public function __sleep()
    {
        return array('id');
    }

    /**
     * Set login
     *
     * @param string $login
     * @return HdvCompte
     */
    public function setLogin($login)
    {
        $this->login = $login;
    
        return $this;
    }

    /**
     * Get login
     *
     * @return string 
     */
    public function getLogin()
    {
        return $this->login;
    }

    /**
     * Set diablo3Compte
     *
     * @param \D3hdv\Diablo3Bundle\Entity\D3Compte $diablo3Compte
     * @return HdvCompte
     */
    public function setDiablo3Compte(\D3hdv\Diablo3Bundle\Entity\D3Compte $diablo3Compte)
    {
        $this->diablo3Compte = $diablo3Compte;
    
        return $this;
    }

    public function removeDiablo3Compte()
    {
        $this->diablo3Compte = NULL;
    
        return $this;
    }

    /**
     * Get diablo3Compte
     *
     * @return \D3hdv\Diablo3Bundle\Entity\D3Compte 
     */
    public function getDiablo3Compte()
    {
        return $this->diablo3Compte;
    }

    /**
     * Add ObjetsEnVente
     *
     * @param \D3hdv\HdvBundle\Entity\HdvVente $objetsEnVente
     * @return HdvCompte
     */
    public function addObjetsEnVente(\D3hdv\HdvBundle\Entity\HdvVente $objetsEnVente)
    {
        $this->ObjetsEnVente[] = $objetsEnVente;
    
        return $this;
    }

    /**
     * Remove ObjetsEnVente
     *
     * @param \D3hdv\HdvBundle\Entity\HdvVente $objetsEnVente
     */
    public function removeObjetsEnVente(\D3hdv\HdvBundle\Entity\HdvVente $objetsEnVente)
    {
        $this->ObjetsEnVente->removeElement($objetsEnVente);
    }

    /**
     * Get ObjetsEnVente
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getObjetsEnVente()
    {
        return $this->ObjetsEnVente;
    }

    /**
     * Add notification
     *
     * @param \D3hdv\HdvBundle\Entity\HdvNotification $notification
     * @return HdvCompte
     */
    public function addNotification(\D3hdv\HdvBundle\Entity\HdvNotification $notification)
    {
        $this->notification[] = $notification;
    
        return $this;
    }

    /**
     * Remove notification
     *
     * @param \D3hdv\HdvBundle\Entity\HdvNotification $notification
     */
    public function removeNotification(\D3hdv\HdvBundle\Entity\HdvNotification $notification)
    {
        $this->notification->removeElement($notification);
    }

    /**
     * Get notification
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getNotification()
    {
        return $this->notification;
    }
}
